package com.example.entity;

import lombok.Data;

/**
 * 接口返回值实体类
 * @author 李平
 * @Date 2022-5-1
 */
@Data
public class ResponseEntity {

    private Integer code;
    private String msg;
    private Object data;
    private Integer count;

    //返回成功
    public static ResponseEntity ok(Object data){
        ResponseEntity r = new ResponseEntity();
        r.setCode(0);
        r.setCount(0);
        r.setData(data);
        r.setMsg("操作执行成功");
        return r;
    }
    public static ResponseEntity ok(Object data, int count){
        ResponseEntity r = new ResponseEntity();
        r.setCode(0);
        r.setCount(count);
        r.setData(data);
        r.setMsg("操作执行成功");
        return r;
    }
    public static ResponseEntity ok(String msg, Object data, int count){
        ResponseEntity r = new ResponseEntity();
        r.setCode(0);
        r.setCount(count);
        r.setData(data);
        r.setMsg(msg);
        return r;
    }

    //返回错误
    public static ResponseEntity err(String msg){
        ResponseEntity r = new ResponseEntity();
        r.setCode(-1);
        r.setCount(0);
        r.setData(null);
        r.setMsg(msg);
        return r;
    }
    public static ResponseEntity err(String msg, Object data){
        ResponseEntity r = new ResponseEntity();
        r.setCode(-1);
        r.setCount(0);
        r.setData(data);
        r.setMsg(msg);
        return r;
    }

    //打包全部参数
    public static ResponseEntity pk(int code, String msg, Object data, int count){
        ResponseEntity r = new ResponseEntity();
        r.setCode(code);
        r.setCount(count);
        r.setData(data);
        r.setMsg(msg);
        return r;
    }
}
